package mirrormonkey.core.member;

import com.jme3.network.MessageConnection;

public final class SearchCompatibleKey extends SearchKey {

	public SearchCompatibleKey(MessageConnection connection, Object[] parameters) {
		super(connection, parameters);
	}

	@Override
	public final boolean equals(Object o) {
		if (!PresentKey.class.isInstance(o)) {
			return false;
		}
		PresentKey other = (PresentKey) o;
		Object[] parameters = getParameters();
		for (int i = 0; i < parameters.length; i++) {
			if (parameters[i] != null) {
				if (!other.data.interpreters[i].applies(parameters[i])) {
					return false;
				}
				Class<?> pc = other.data.interpreters[i].fetchClass(
						getConnection(), parameters[i]);
				if (pc != null
						&& !other.data.constr.getParameterTypes()[i]
								.isAssignableFrom(pc)) {
					return false;
				}
			}
		}
		return true;
	}

}
